package com.zhongwang.business.module.quoteManage.quoteManageController;

import com.zhongwang.business.base.BaseController;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.gen.entity.User;
import com.zhongwang.business.module.quoteManage.quoteManageDao.QuotationApproveDao;
import com.zhongwang.business.module.quoteManage.quoteManageDao.QuotationMainDao;
import com.zhongwang.business.module.quoteManage.quoteManageModel.QuotationMainModel;
import com.zhongwang.business.module.quoteManage.quoteManageService.QuoteTaskService;
import com.zhongwang.business.module.quoteManage.quoteManageService.QuoteApproveService;
import com.zhongwang.business.module.system.log.LogService;
import com.zhongwang.business.module.system.user.UserService;
import com.zhongwang.business.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 报价审核管理
 * @author zcy
 * @time: 2020-10-24
 */

@Controller
@RequestMapping("/quoteManage")
public class QuoteApproveController extends BaseController {
    @Autowired
    private QuoteApproveService quoteApproveService;
    @Autowired
    private UserService userService;
    @Autowired
    private QuotationApproveDao quotationApproveDao;
    @Autowired
    private QuotationMainDao quotationMainDao;
    @Autowired
    private LogService logService;

    /**
     * 报价审核页面
     * @param
     * @return 页面路径
     */
    @GetMapping("/quoteApprove/page")
    @RequiresPermissions({"quo:audit:view"})
    public String page(Model model) {
        User user = ShiroUtils.getUser();
        model.addAttribute("sysUserModel", quotationApproveDao.findNowNodeByAccount(user.getAccount()));
        return "quoteManage/quoteApprove";
    }
    /**
     * 报价审核列表
     * @param query
     * @return
     */
    @ResponseBody
    @PostMapping("/quoteApprove/list")
    public JsonResult quoteApplist(QuotationMainModel query){
        startPage();
        List<QuotationMainModel> list = quoteApproveService.findQttApproveList(query);
        return jsonResult(list);
    }

    /**
     * 跳转至报价单审核页面
     * @param quoteId,model
     * @return 页面路径
     */
    @GetMapping("/appQuotation/quoteId/{quoteId}")
    @RequiresAuthentication
    @RequiresPermissions({"quo:audit:check"})
    public String appPage(@PathVariable("quoteId") Integer quoteId, Model model) {
        QuotationMainModel quotationMain = quotationApproveDao.selectQttInfo(quoteId);
        model.addAttribute("quotationMain",quotationMain);
        model.addAttribute("qtts", quotationMainDao.selectQttList(quoteId));
        User user = ShiroUtils.getUser();
        model.addAttribute("sysUserModel", quotationApproveDao.findNowNodeByAccount(user.getAccount()));
        model.addAttribute("payItems",quotationMainDao.selectQttItemList(quotationMain.getQuoteId()));
        List<QuotationMainModel> appList= quotationApproveDao.selectAppList(quoteId);
        model.addAttribute("appList",appList);
        return "quoteManage/appQuotation";
    }

    /**
     * 审核通过
     * @param quotationMainModel
     * @return 审核结果
     */
    @ResponseBody
    @PostMapping("/quoteApprove/appQtt")
    public JsonResult appQtt(QuotationMainModel quotationMainModel){
        return quoteApproveService.appQtt(quotationMainModel) ;
    }
    /**
     * 审核驳回
     * @param quotationMainModel
     * @return 审核结果
     */
    @ResponseBody
    @PostMapping("/quoteApprove/rejQtt")
    public JsonResult rejQtt(QuotationMainModel quotationMainModel){
        return quoteApproveService.rejQtt(quotationMainModel);
    }

//    /**
//     * 审核意见列表数据
//     * @param query
//     * @return
//     */
//    @ResponseBody
//    @PostMapping("/quoteApprove/appCommentList")
//    public JsonResult appCommentList(QuotationMainModel query){
//        List<QuotationMainModel> list = quoteApproveService.findAppCommentList(query);
//        return jsonResult(list);
//    }
}
